package org.ayachinene.leetcode.problems;

public class P2325 {

    static class Solution {
        public String decodeMessage(String key, String message) {
            char[] alphabet = new char[256];
            boolean[] occur = new boolean[256];
            int i = 'a';
            int j = 0;
            while (i <= 'z') {
                char c = key.charAt(j++);
                if (c != ' ' && !occur[c]) {
                    alphabet[c] = (char) i++;
                    occur[c] = true;
                }
            }

            StringBuilder res = new StringBuilder();
            for (char c : message.toCharArray()) {
                res.append(c == ' ' ? c : alphabet[c]);
            }
            return res.toString();
        }
    }
}
